/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.security.Security;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author Alice
 */
public class EmailCASA {
  public EmailCASA(){}  

    public static void main(String nomeU,String cognomeU,String email,String nomeP,String descr,String categ,float off,Timestamp time) throws AddressException, MessagingException {
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.smtp.host", "smtp.gmail.com");
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.auth", "true");
props.put( "mail.debug", "true" );
final String username = "gokuali91@gmail.com";
final String password = "gogeta2011";
Session session = Session.getInstance(props, new Authenticator(){

    protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}});
// — Create a new message –
Message msg = new MimeMessage(session);
// — Set the FROM and TO fields –
msg.setFrom(new InternetAddress(username + ""));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(email,false));
msg.setSubject("WeBuy-Asta: avviso Cancellazione Asta");
msg.setText("Spet.Le "+nomeU+" "+cognomeU+", \n"+
            "La sua Offerta per questo prodotto:\n"+
              "\n"+
              "NOME PRODOTTO: "+nomeP+";\n"+
              "DESCRIZIONE PRODOTTO: "+descr+";\n"+
              "CATEGORIA: "+categ+";\n"+
              "OFFERTA: "+off+" € ;\n"+
              "DATA OFFERTA: "+time+";\n"+
              "\n"+
              "l'Amministratore di WeBuy-Asta Online l'avvisa che l'Asta a cui Lei partecipava è stata Cancellata.\n"+
              "Ci scusiamo.\nDistinti Saluti.\n"+
              "WeBuy"+
               "\n\n\n"+new Date()
             );
msg.setSentDate(new Date());
Transport.send(msg);
    
}
}